﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien1.DAO;
using QuanLyThuVien1.BUS;
using QuanLyThuVien1.DTO;

namespace QuanLyThuVien1.GUI
{
    public partial class Fr_BaoCao : Form
    {
        public Fr_BaoCao()
        {
            InitializeComponent();
        }

        private void Bt_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bt_ThongKe_Click(object sender, EventArgs e)
        {
            try
            {
                CTongQuat t = new CTongQuat();
                textBox1.Text = t.demTongLuotMuon().ToString();
                DataTable d = new DataTable();
                DataTable d1 = new DataTable();
                d = t.demSachTheoLoai();
                d1 = t.demSoLuotMuon();
                dGTheLoai.DataSource = d1;
                string s ;
                int n = d.Rows.Count;
                int m =  d1.Rows.Count;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (d.Rows[i][0].ToString() == d1.Rows[j][0].ToString())
                        {
                            float n1 = float.Parse(d1.Rows[j][1].ToString()) / (float.Parse(d.Rows[i][1].ToString())+ float.Parse(d1.Rows[j][1].ToString())) ;
                            s = n1.ToString();
                            dGTheLoai.Rows[j].Cells[0].Value = s;
                        }
                    }
                }
               
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
        }

        private void bt_Th_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Fr_BaoCao_Load(object sender, EventArgs e)
        {
            tb_Ngay.Text = DateTime.Today.Date.ToShortDateString();
            tb_ngay1.Text = DateTime.Today.Date.ToShortDateString();

        }

        private void bt_Tk_Click(object sender, EventArgs e)
        {
            try
            {
                CTongQuat t = new CTongQuat();
                DataTable d = new DataTable();
                DataTable d1 = new DataTable();
                d  = t.SachTraTre_Bus();
                int n = d.Rows.Count;
               //d_TraTre.DataSource = d;
                
               for (int i = 0; i < n-1; i++)
               {
                   TimeSpan time = DateTime.Parse(DateTime.Today.Date.ToShortDateString()) - DateTime.Parse(d.Rows[i][2].ToString());
                   if (time.TotalDays <= 0)
                   {
                       
                       d.Rows.RemoveAt(i);
                   }
               }

               d_TraTre.DataSource = d;
                    
                        int n1 = d_TraTre.Rows.Count - 1;
                        d_TraTre.Columns.RemoveAt(3);
                        for (int j = 0; j < n1; j++)
                        {
                            int n2 = 0;
                            TimeSpan time1 = DateTime.Today.Date - DateTime.Parse(d.Rows[j][2].ToString());
                      
                           d_TraTre.Rows[j].Cells[0].Value = time1.TotalDays;
                          
                        }
                    

             
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }

        private void bt_Th1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bt_Tk1_Click(object sender, EventArgs e)
        {
            CDocGia_Bus d = new CDocGia_Bus();
            tb_tienNo.Text = d.TinhTongTienNo();
            d_DGNoTien.DataSource = d.LayDanhSachDGNoTien();
        }

       
    }
}